﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class DocumentTypeDAL : SqlDataProvider
    {
        #region[DocumentType_GetById]
        public List<DocumentType> DocumentType_GetById(string Id)
        {
            List<Entity.DocumentType> list = new List<Entity.DocumentType>();
            using (SqlCommand dbCmd = new SqlCommand("sp_DocumentType_GetById", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(DocumentType.DocumentTypeIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[DocumentType_GetByTop]
        public List<DocumentType> DocumentType_GetByTop(string Top, string Where, string Order)
        {
            List<Entity.DocumentType> list = new List<Entity.DocumentType>();
            using (SqlCommand dbCmd = new SqlCommand("sp_DocumentType_GetByTop", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(DocumentType.DocumentTypeIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[DocumentType_GetByAll]
        public List<DocumentType> DocumentType_GetByAll(string Lang)
        {
            List<Entity.DocumentType> list = new List<Entity.DocumentType>();
            using (SqlCommand dbCmd = new SqlCommand("sp_DocumentType_GetByAll", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(DocumentType.DocumentTypeIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[DocumentType_Insert]
        public bool DocumentType_Insert(DocumentType data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_DocumentType_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("DocumentType");
            return true;
        }
        #endregion
        #region[DocumentType_Update]
        public bool DocumentType_Update(DocumentType data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_DocumentType_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("DocumentType");
            return true;
        }
        #endregion
        #region[DocumentType_Delete]
        public bool DocumentType_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_DocumentType_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("DocumentType");
            return true;
        }
        #endregion

    }
}
